- if @listing.closed?
  .listing-view-admin-links
    .listing-view-admin-link
      .icon-with-text-container
        = icon_tag("lock", ["icon-part"])
        .text-part= t("listings.reply_link.listing_closed")
    - if @listing_presenter.is_authorized
      .listing-view-admin-link
        %a.action-link{href: edit_listing_path(@listing)}
          .icon-with-text-container
            = icon_tag("unlock", ["icon-part"])
            .text-part= t("listings.edit_links.reopen_listing")
      .listing-view-admin-link
        = link_to delete_listing_path(@listing), data: {confirm: t("listings.deleting_a_listing_cannot_be_undone")},
          method: "delete", class: 'icon-with-text-container' do
          = icon_tag("trash", ["icon-part"])
          .text-part= t("listings.edit_links.delete_listing")

- else

  - if @listing_presenter.is_author
    = render partial: "delivery_opts", locals: { delivery_opts: @listing_presenter.delivery_opts, is_author: @listing_presenter.is_author }
  - else

    = form_tag @listing_presenter.form_path, :method => :get, :id => "booking-dates" do

      - if @listing_presenter.quantity_per_day_or_night?
        - @listing_presenter.blocked_dates_result.on_success do |blocked_dates|
          - content_for :extra_javascript do
            :javascript
              window.ST.FromToDatePicker.setupPerDayOrNight(#{raw @listing_presenter.datepicker_per_day_or_night_setup(blocked_dates).to_json});
          .input-daterange.input-group.clearfix#datepicker{:data => {:locale => I18n.locale, :dateformat => t("datepicker.format")}}
            .datepicker-start-wrapper
              = label_tag t(".booking_from")
              %input.input-sm.form-control.required#start-on{:type => 'text', :name => "start_on_datepicker", :placeholder => t("datepicker.format"), :data => { :output => "booking-start-output" }, :autocomplete => 'off' }
              %input#booking-start-output{:type => 'hidden', :name => 'start_on'}

            .datepicker-end-wrapper
              = label_tag t(".booking_to")
              %input.input-sm.form-control.required#end-on{:type => 'text', :name => "end_on_datepicker", :placeholder => t("datepicker.format"), :data => { :output => "booking-end-output" }, :autocomplete => 'off'}
              %input#booking-end-output{:type => 'hidden', :name => 'end_on'}

        - @listing_presenter.blocked_dates_result.on_error do
          = t("listings.listing_actions.unable_load_availability")

      - elsif @listing_presenter.booking_per_hour?
        .input-daterange.input-group.clearfix
          .datepicker-per-hour
            .field
              = label_tag t(".booking_date")
              %input.input-sm.form-control.required#start-on{ :type => 'text',
                :name => "start_on_show", :placeholder => t("datepicker.format"), :autocomplete => 'off',
                :data => { :locale => I18n.locale, :dateformat => t("datepicker.format") },
                :required => true }
            .field
              = label_tag t(".start_time")
              = select_tag 'start_time', options_for_select([]), id: 'start_time', :required => true
            .field
              = label_tag t(".end_time")
              = select_tag 'end_time', options_for_select([]), id: 'end_time', :required => true
          = hidden_field_tag 'per_hour', '1'
        - content_for :extra_javascript do
          = js_t ["listings.listing_actions.select_one"], true
          :javascript
            window.ST.FromToDatePicker.setupPerHour(#{raw @listing_presenter.datepicker_per_hour_setup.to_json});

      - elsif @listing_presenter.listing_unit_type.present?
        - content_for :extra_javascript do
          :javascript
            $("#booking-dates").validate({
              errorPlacement: function(error, element) {
                if (element.is("#quantity")) {
                  error.insertAfter(".quantity-wrapper");
                } else {
                  error.insertAfter(element);
                }
              }
            });
            window.ST.initializeQuantityValidation({validate: "positiveIntegers", input: "quantity", errorMessage: "#{t("errors.messages.positive_number")}" });
            if ("#{@listing_presenter.delivery_type}" == "shipping" && #{@listing_presenter.shipping_price_additional != nil}) {
              window.ST.initializeShippingPriceTotal(#{raw @listing_presenter.currency_opts.to_json}, '#quantity', '.delivery-price-value');
            }

        .quantity-wrapper.input-group.clearfix
          .quantity-label-wrapper
            %label.quantity-label{for: 'quantity'}
              = ListingViewUtils.translate_quantity(@listing.unit_type, @listing.unit_selector_tr_key)
          .quantity-input.input-sm.required
            %input#quantity{type: 'number', placeholder: t("listings.quantity_placeholder"), name: 'quantity', value: 1, min: 1, step: 1}

      = render partial: "delivery_opts", locals: { delivery_opts: @listing_presenter.delivery_opts, is_author: @listing_presenter.is_author }

      = hidden_field_tag(:listing_id, @listing.id)

      - if @listing_presenter.buyer_fee?
        .row
          .col-12
            %span.buyer-fees
              = t('.marketplace_fees_may_apply')
      - if @listing_presenter.quantity_per_day_or_night?
        - @listing_presenter.blocked_dates_result.on_success do
          %button.enabled-book-button
            .content
              = action_button_label(@listing)

        - @listing_presenter.blocked_dates_result.on_error do
          %button.disabled-book-button{disabled: true}
            .content
              = action_button_label(@listing)
      - else
        %button.enabled-book-button
          .content
            = action_button_label(@listing)

    - if @listing_presenter.payments_enabled?
      .row
        .col-12
          = render :partial => "listing_conversations/payment_methods", locals: { stripe_in_use: @listing_presenter.stripe_in_use, paypal_in_use: @listing_presenter.paypal_in_use }

  - if @listing_presenter.is_authorized
    .listing-view-admin-links
      - if @listing_presenter.approval_in_use?
        - if @listing.approval_pending?
          .listing-view-admin-link
            %span.icon-with-text-container
              = icon_tag("pending", ["icon-part"])
              .text-part= t("listings.edit_links.listing_is_pending")
        - elsif @listing.approval_rejected?
          .listing-view-admin-link
            %span.icon-with-text-container
              = icon_tag("cross", ["icon-part"])
              .text-part= t("listings.edit_links.listing_is_rejected")
        - if @listing_presenter.pending_admin_approval?
          .listing-view-admin-link
            %a.icon-with-text-container{href: approve_admin_community_listing_path(@current_community, @listing)}
              = icon_tag("check", ["icon-part"])
              .text-part= t("listings.edit_links.approve_listing")
          .listing-view-admin-link
            %a.icon-with-text-container{href: reject_admin_community_listing_path(@current_community, @listing)}
              = icon_tag("cross", ["icon-part"])
              .text-part= t("listings.edit_links.reject_listing")
      .listing-view-admin-link
        %a.icon-with-text-container{href: edit_listing_path(@listing)}
          = icon_tag("edit", ["icon-part"])
          .text-part= t("listings.edit_links.edit_listing")
      - if @listing_presenter.show_manage_availability
        - availability_link_id = "edit-listing-availability-#{SecureRandom.urlsafe_base64(5)}"
        .listing-view-admin-link
          - if @listing_presenter.booking_per_hour?
            %a.icon-with-text-container{id: availability_link_id, href: "#manage-working-hours"}
              = icon_tag("calendar", ["icon-part"])
              .text-part= t("web.listings.edit_listing_availability")
            = react_component("ListingWorkingHoursApp", props: @listing_presenter.working_hours_props.merge({ availability_link_id: availability_link_id }), prerender: false)
          - elsif APP_CONFIG.harmony_api_in_use
            %a.icon-with-text-container{id: availability_link_id, href: "#manage-availability"}
              = icon_tag("calendar", ["icon-part"])
              .text-part= t("web.listings.edit_listing_availability")
            = react_component("ManageAvailabilityApp", props: @listing_presenter.manage_availability_props.merge({ availability_link_id: availability_link_id }), prerender: false)
      .listing-view-admin-link
        %a.icon-with-text-container{href: close_person_listing_path(@current_user, @listing), data: { method: "put", remote: "true"}}
          = icon_tag("lock", ["icon-part"])
          .text-part= t("listings.edit_links.close_listing")
      .listing-view-admin-link
        = link_to delete_listing_path(@listing), data: {confirm: t("listings.deleting_a_listing_cannot_be_undone")},
          method: "delete", class: 'icon-with-text-container' do
          = icon_tag("trash", ["icon-part"])
          .text-part= t("listings.edit_links.delete_listing")

      - if @listing_presenter.is_marketplace_admin
        .listing-view-admin-link
          = link_to move_to_top_person_listing_path(@current_user, @listing), data: { method: "put" } do
            .icon-with-text-container
              = icon_tag("star", ["icon-part"])
              .text-part= t("listings.edit_links.move_to_top")

        .listing-view-admin-link
          = link_to show_in_updates_email_person_listing_path(@current_user, @listing), data: { method: "put", remote: "true" }, :id => "add-to-updates-email"  do
            .icon-with-text-container
              = icon_tag("mail", ["icon-part"])
              .text-part#add-to-updates-email-text{data: {:"action-loading" => t("listings.edit_links.show_in_updates_email_loading"), :"action-error" => t("listings.edit_links.show_in_updates_email_error"), :"action-success"=> t("listings.edit_links.show_in_updates_email_success")}}= t("listings.edit_links.show_in_updates_email")

